package com.ashlikun.scan.simple

import android.content.Context
import android.graphics.BlendMode
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.os.Build
import android.util.AttributeSet
import android.view.View
import androidx.annotation.RequiresApi

/**
 * 作者　　: 李坤
 * 创建时间: 2024/2/21　15:31
 * 邮箱　　：496546144@qq.com
 *
 * 功能介绍：
 */
@RequiresApi(Build.VERSION_CODES.Q)
class ViewTest @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) : View(context, attributeSet, def) {
    val paint by lazy {
        Paint().also {
            it.isAntiAlias = true
            it.color = 0xFF0000.toInt()
            it.alpha = 0
            it.blendMode = BlendMode.CLEAR
        }
    }
    val paint2 by lazy {
        Paint().also {
            it.isAntiAlias = true
            it.color = 0x000000.toInt()
            it.alpha = 120
        }
    }
    val paint3 by lazy {
        Paint().also {
            it.isAntiAlias = true
            it.color = 0xFF0000.toInt()
            it.alpha = 120
        }
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
//        canvas.drawRect(Rect(0, 0, width, height), paint3)
        canvas.drawRect(Rect(0, 0, width, height), paint2)
        canvas.drawRect(Rect(200, 400, width - 200, height - 400), paint)
    }
}